//
//  NvMoreFilterCell.m
//  SDKDemo
//
//  Created by ms20180425 on 2018/5/29.
//  Copyright © 2018年 meishe. All rights reserved.
//

#import "NvMoreAssetCell.h"
#import "UIImageView+WebCache.h"

@interface NvMoreAssetCell()

@property (nonatomic, strong) NSString *string;

@end

@implementation NvMoreAssetCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self addSubviews];
    }
    return self ;
}

- (void)addSubviews{
    self.coverView = [UIImageView new];
    self.coverView.contentMode = UIViewContentModeScaleAspectFit;
    self.coverView.layer.masksToBounds = YES;
    self.coverView.layer.cornerRadius = 45 * SCREANSCALE / 2;
    
    self.nameLabel = [UILabel new];
    self.nameLabel.textColor = [UIColor nv_colorWithHexRGB:@"#373B3D"];
    self.nameLabel.font = [NvUtils fontWithSize:12 * SCREANSCALE];
    
    self.drawLabel = [UILabel new];
    self.drawLabel.textColor = [UIColor nv_colorWithHexRGB:@"#373B3D"];
    self.drawLabel.font = [NvUtils fontWithSize:11 * SCREANSCALE];
    
    self.sizeLabel = [UILabel new];
    self.sizeLabel.textColor = [UIColor nv_colorWithHexRGB:@"#373B3D"];
    self.sizeLabel.font = [NvUtils fontWithSize:12 * SCREANSCALE];
    
    self.download = [NvDownloadBtn buttonWithType:UIButtonTypeCustom];
    [self.download addTarget:self action:@selector(downloadBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:self.coverView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.drawLabel];
    [self.contentView addSubview:self.sizeLabel];
    [self.contentView addSubview:self.download];
    
    [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(13 * SCREANSCALE);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.offset(45 * SCREANSCALE);
        make.height.offset(45 * SCREANSCALE);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.coverView.mas_right).offset(15 * SCREANSCALE);
        make.top.equalTo(self.coverView.mas_top);
    }];
    
    [self.drawLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.nameLabel.mas_leading);
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    
    [self.sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.nameLabel.mas_leading);
        make.bottom.equalTo(self.coverView.mas_bottom);
    }];
    
    [self.download mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(- 13 * SCREANSCALE);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.offset(60 * SCREANSCALE);
        make.height.offset(27 * SCREANSCALE);
    }];
    
    UILabel *Line = [UILabel new];
    Line.backgroundColor = [UIColor nv_colorWithHexRGB:@"#979797"];
    [self.contentView addSubview:Line];
    [Line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(SCREEN_WDITH);
        make.height.offset(1);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
}

- (void)setModel:(NvAssetCellModel *)model{
    _model = model;
    switch (_type) {
        case ASSET_THEME:
            _string = @"画幅";
            break;
        case ASSET_FILTER:
            _string = @"画幅";
            break;
        case ASSET_CAPTION_STYLE:
            _string = @"画幅";
            break;
        case ASSET_ANIMATED_STICKER:
            _string = @"画幅";
            break;
        case ASSET_VIDEO_TRANSITION:
            _string = @"画幅";
            break;
        case ASSET_CAPTURE_SCENE:
            _string = @"画幅";
            break;
        case ASSET_PARTICLE:
            _string = @"画幅";
            break;
        default:
            _string = @"画幅";
            break;
    }
    self.nameLabel.text = model.displayName;
    [self.coverView sd_setImageWithURL:[NSURL URLWithString:model.cover]];//[NvUtils imageWithName:model.cover];
    self.sizeLabel.text = [NSString stringWithFormat:@"大小：%@",model.size];
    self.drawLabel.text = [NSString stringWithFormat:@"%@：%@",_string,model.draw];
    switch (self.model.state) {
        case NODownload:
            self.download.stateTitle = @"下载";
            break;
        case Downloading:
            break;
        case DownloadError:
            self.download.stateTitle = @"重试";
            break;
        case Finish:
            self.download.stateTitle = @"已下载";
            break;
        case Update:
            self.download.stateTitle = @"更新";
            break;
        default:
            break;
    }
}

- (void)downloadBtn{
    [_delegate nvMoreAssetCell:self nvAssetItem:self.model];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
